package com.dsg.service.system.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dsg.dao.system.DsgSysParameterMapper;
import com.dsg.entity.system.DsgSysParameter;
import com.dsg.service.system.IDsgSysParameterService;
import com.dsg.util.EhCacheNames;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 參數表 服务实现类
 * </p>
 *
 * @author system
 * @since 2020-07-03
 */
@Service
public class DsgSysParameterServiceImpl extends ServiceImpl<DsgSysParameterMapper, DsgSysParameter> implements IDsgSysParameterService {

    @Autowired
    private DsgSysParameterMapper dsgSysParameterMapper;

    @Override
    @Cacheable(value = EhCacheNames.sysParameterName, key = "'DsgSysParameter_'+#paraType")
    public List<DsgSysParameter> selectByList(String paraType) {
        QueryWrapper<DsgSysParameter> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("PARA_KEY as paraKey,PARA_VALUE as paraValue");
        queryWrapper.eq("PARA_TYPE", paraType);
        queryWrapper.eq("STATUS", 1);
        return dsgSysParameterMapper.selectList(queryWrapper);
    }

    @Override
    @Cacheable(value = EhCacheNames.sysParameterName, key = "'DsgSysParameter_'+#paraType+'_'+#paraKey")
    public DsgSysParameter selectDsgSysParameter(String paraType, String paraKey) {
        QueryWrapper<DsgSysParameter> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("PARA_KEY as paraKey,PARA_VALUE as paraValue");
        queryWrapper.eq("PARA_TYPE", paraType);
        queryWrapper.eq("PARA_KEY", paraKey);
        queryWrapper.eq("STATUS", 1);
        return dsgSysParameterMapper.selectOne(queryWrapper);
    }

    @Override
    public Page selectDsgSysParameterList(Page page, DsgSysParameter dsgSysParameter) {
        return page.setRecords(dsgSysParameterMapper.selectDsgSysParameterList(page, dsgSysParameter));
    }
}
